package org.sny7.openOfflineList.gui;

import java.util.List;

import javax.swing.JList;
import javax.swing.ListSelectionModel;

import org.sny7.openOfflineList.bean.Game;
import org.sny7.openOfflineList.listener.GameListFilterModel;
import org.sny7.openOfflineList.listener.GameListItemClick;
import org.sny7.openOfflineList.listener.GameListItemRenderer;

public class GameList extends JList {

	private static GameList gameList = init();
	private static GameListFilterModel listModel;
	
	private static final long serialVersionUID = 1L;
	
	private GameList() {
		
	}
	
	public static GameList getGameList() {
		return gameList;
	}
	
	private static GameList init() {
		GameList gameList = new GameList();
		listModel = new GameListFilterModel();
		gameList.setModel(listModel);
		gameList.setCellRenderer(new GameListItemRenderer());
		gameList.addMouseListener(new GameListItemClick());
		gameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		
		return gameList;
	}
	
	public static void addAll(List<Game> gameList) {
		listModel.addAll(gameList);
		listModel.setTitle("");
	}
	
	public static void search(String text) {
		listModel.setTitle(text);
	}
	
	public static void clear() {
		listModel.clear();
	}

}
